package org.jeecg.modules.strategy.component;

import org.jeecg.modules.strategy.mapper.AnalyticsMapper;
import org.jeecg.modules.strategy.model.entity.AnalyticsEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

import javax.annotation.Resource;

@Component
public class HomePagePipeline implements Pipeline {
    private AnalyticsMapper analyticsMapper;

    @Autowired
    public HomePagePipeline(AnalyticsMapper analyticsMapper) {
        this.analyticsMapper = analyticsMapper;
    }

    @Transactional
    @Override
    public void process(ResultItems resultItems, Task task) {
        AnalyticsEntity analyticsEntity = resultItems.get("analyticsEntity");
        if (analyticsEntity != null) {
            analyticsMapper.insert(analyticsEntity);
        }
    }
}
